//const Store = require("electron-store");
/**
 * 全局参数
 */
import Store from "electron-store";
import { uuid } from "../utils/uuid";
import RES from "../utils/res";

const store = new Store();

const key = "setting";

const defaultSetting = {
  configPath: RES.getConfigPath(),
  templatePath: RES.buildPath("template"),
  translatePath: RES.buildPath("translate"),
};

function set(setting) {
  let sss = {};
  Object.keys(defaultSetting).forEach((key) => {
    sss[key] = setting[key];
  });
  sss.id = uuid();
  store.set(key, sss);
  return;
}

function get() {
  var setting = store.get(key);
  if (setting == null) {
    set(defaultSetting);
    setting = defaultSetting;
  }

  return setting;
}

function reset() {
  store.set(key, defaultSetting);
}

let SettingStore = {
  set,
  get,
  reset,
};

export default SettingStore;
